var canvas = document.getElementById("main");
var height = document.documentElement.clientHeight || document.body.clientHeight;
var width = document.documentElement.clientWidth || document.body.clientWidth;
var title = document.getElementById("title");
$(document).ready(function() {
  canvas.width = width;
  canvas.height = height;
  init();
});

var data =[];   //数据
var index = -1;

function init() {
  $.ajax({
    url: "http://git.wucai.com/service_new/?m=Home&c=Search&a=demo&callback=?",
    success: function(result) {
        data = disposeData(result);
        handleSwitch();
    },
    jsonpCallback: "jsonpCallback",
    dataType: "jsonp",
    jsonp: "callback"
  });
}

function disposeData(result){
    data = result.map(function(item) {
        var obj = {
          name: item.platform,
          children: [],
          size:10000
        };

        var arr = [];
        for (var i in item.char) {
            var itemArr = [item.char[i],parseInt(item.charsize[i]*25)]
            arr.push(itemArr);
        }
        obj.children = arr;
        return obj;
      });
    return data;
}

function handleSwitch(){
    index++;
    if(index>=data.length){
        index=0;
    }
    Option.list = data[index].children;
    title.innerHTML = data[index].name;
    setData(Option);
}

console.log("浏览器是否支持",WordCloud.isSupported);
console.log("最小字体大小偏好检测",WordCloud.minFontSize);
function setData(Option) {
    console.log(Option);
    WordCloud(canvas, Option);
}

Option = {
    title:"",
    fontWeight:"600",
    minSize:"12",
    list: [['foo', 120], ['bar', 60]] ,
    backgroundColor:"rgba(255,255,255,1)",
    wait:"1",
    shape:"cardioid",
    click:function(res){
        console.log(res);
    },
    origin:[width/2,height/6]
}

